import java.lang.Throwable;
import java.util.Scanner;
import java.lang.*;
import java.util.InputMismatchException;
class WS3 {
public static void main(String[] args) {
      Vehicle []v=new Vehicle[3];
      v[0]=new Vehicle("Thong Nhat","Phuong Hoang",50);
      v[1]=new Car("Mercedes","s360",200000,"white");
      VehicleCollection collection=new VehicleCollection();
      collection.add(v[0]);
      collection.add(v[1]);
      collection.input();
      collection.display();
    }
    
}
class Vehicle{
    String mark,model;
    double price;
    Vehicle(){};
    Vehicle(String m,String mo,double p){
        mark=m;
        model=mo;
        price=p;
    }
    public void input(){
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the mark: ");
        mark=sc.nextLine();
        System.out.print("Enter model: ");
        model=sc.nextLine();
        boolean keep=true;
        do{
            try{
                System.out.print("Enter price: ");
                price=sc.nextDouble();
                if(price<=0) throw new myException("Requirement positive integer");
                keep=false;
            }
            catch(myException e1){
                System.out.println(e1.getMessage()); 
            }
          catch(InputMismatchException e){
                System.out.println(e.toString());
           }
            finally{
                sc.nextLine();
            }
            
        }while(keep==true);
        
    }
    
    public void display(){
        System.out.print(mark+"/"+model+"/"+price);
    }
}
class myException extends Exception{
    myException(String str){
        super(str);
    }
}
class Car extends Vehicle{
    String color;
    Car(){}
    Car(String m,String mo,double p,String co){
        super(m,mo,p);
        color=co;
    }
    public void input(){
        Scanner sc=new Scanner(System.in);
        super.input();
        System.out.print("Enter color: ");
        color=sc.nextLine();
    }
    public void display(){
        super.display();
        System.out.print("/"+color);
    }
}

class Truck extends Vehicle{
    int truckload;
    Truck(){}
    Truck(String m,String mo,double p,int t){
        super(m,mo,p);
        truckload=t;
    }
    public void input(){
        Scanner sc=new Scanner(System.in);
        super.input();
        System.out.print("Enter truckload: ");
        truckload=sc.nextInt();
    }
    public void display(){
        super.display();
        System.out.print("/"+truckload);
    }
}

class VehicleCollection{
     final int MAX=100;
    Vehicle []list=new Vehicle[MAX];
    int count=0;
   
    public VehicleCollection(){}
    
    public void input(){
        Scanner sc=new Scanner(System.in);
        int keep=1;
        while(true){
            System.out.print("Enter type of Vehicle: ");
            keep=sc.nextInt();
            if(keep==0) break;
            else if(keep==1){
                list[count]=new Car();
                list[count].input();
                count++;
                
            }
            else{
                list[count]=new Truck();
                list[count].input();
                count++;
            }
        }
    }
    public void add(Vehicle vh){
        list[count]=vh;
        count++;
    }
    public void display(){
        for(int i=0;i<count;i++){
            list[i].display();
            System.out.println("");
        }
    }
    
}

